02: UN Votes Report
Note: Use this file as starter code and extra information. Your goal is to create a knitted report file that matches the “UN report to replicate” file linked on the schedule for today. You should replicate the “Summarizing the dataset” section exactly, but use inline R code to replace hard coding the five numbers and years in that section. You should also replicate the “UN Voting Patterns” section - again using inline R code to for the three countries and two years listed - but with one change: use three new countries (or more if you’d like the slight added challenge). Reflect with your neighbor on what you find - use the questions in the Introduction section as a starting point.
Getting started
You should open this document in RStudio. To do so:
- Open your local RStudio program.
- Go to file –> New file –> Quarto document … –> “Create empty document”. This should open a new .qmd file in your Rstudio session. Delete everything in this file so that you have a totally blank document.
- Next, we need to copy this template into your new quarto file.
- come back to this page and click the “code” button at the top of the page.
- Click the “copy” symbol in the upper right corner of the popup file
- Navigate back to your empty .qmd file and “paste” the text there
- You should now be able to see this document in your own session, and you can run code and edit it as you need to! I suggest making a folder (perhaps name it Stat220) that organizes all of the documents for this class, including this one, and saving this document to that folder. Visit the Rstudio in Stat 220 page on the class website for more information on file organization.
Introduction
How do various countries vote in the United Nations General Assembly, how have their voting patterns evolved throughout time, and how similarly or differently do they view certain issues? Answering these questions (at a high level) is the focus of this analysis.
Packages
We will use the tidyverse, lubridate, and scales packages for data wrangling and visualization, and the DT package for interactive display of tabular output, and the unvotes package for the data.
Data
The data we’re using originally come from the unvotes package. In the chunk below we modify the data by joining the various data frames provided in the package to help you get started with the analysis.
unvotes <- un_votes %>%
inner_join(un_roll_calls, by = "rcid") %>%
inner_join(un_roll_call_issues, by = "rcid")UN voting patterns
Let’s create a data visualization that displays how the voting record of the UK & Northern Ireland (together listed under UK) changed over time on a variety of issues, and compares it to two other countries: the US and Turkey.
We can easily change which countries are being plotted by changing which countries the code above filters for. Note that the country name should be spelled and capitalized exactly the same way as it appears in the data. See the Appendix for a list of the countries in the data.
unvotes %>%
filter(country %in% c("United Kingdom", "United States", "Turkey")) %>%
mutate(year = year(date)) %>%
group_by(country, year, issue) %>%
summarize(percent_yes = mean(vote == "yes")) %>%
ggplot(mapping = aes(x = year, y = percent_yes, color = country)) +
geom_point(alpha = 0.4) +
geom_smooth(method = "loess", se = FALSE) +
facet_wrap(~issue) +
scale_y_continuous(labels = percent) +
labs(
title = "Percentage of 'Yes' votes in the UN General Assembly",
subtitle = "1946 to 2019",
y = "% Yes",
x = "Year",
color = "Country"
)
Starter Code
These pieces of code will help you with the R inline coding portions of the report creation:
nrow(unvotes)[1] 857878
ncol(unvotes)[1] 14
[1] 200
[1] 1946
[1] 2019
countrySample <- c("United Kingdom", "United States", "Turkey") # replace with your own interested countries
countrySample[1] "United Kingdom" "United States" "Turkey"
countrySample[1] # replace with other numbers to get the rest of the countries in that object[1] "United Kingdom"
References
- David Robinson (2017). unvotes: United Nations General Assembly Voting Data. R package version 0.2.0.
- Erik Voeten “Data and Analyses of Voting in the UN General Assembly” Routledge Handbook of International Organization, edited by Bob Reinalda (published May 27, 2013).
- Much of the analysis has been modeled on the examples presented in the unvotes package vignette.
Appendix
Below is a list of countries in the data set:
